package com.laxcen.toydemo;

import android.content.Context;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import util.BackgroundMusic;
import util.DefaultHandler;
import util.eventbus.EventBusUtil;
import util.eventbus.MessageEvent;
import util.eventbus.MessageEventType;

public class GameState {
    private Context mContext;
    private static GameState mInstance;

    private GameState(Context context) {
        mContext = context;
        EventBus.getDefault().register(this);
    }

    public static synchronized GameState instance(Context context) {
        if (mInstance == null) {
            mInstance = new GameState(context);
        }
        return mInstance;
    }

    public static int GameStep = EGameStep.FirstOpen;

    public static class EGameStep {

        //首次打开游戏
        public static final int FirstOpen = 10;

        public static final int WaitBLEConnect = 11;
        public static final int WaitMainMenuSelect = 12;

        //游戏已打开,等待操作中
        public static final int AppOpenedGameWait = 20;

        public static final int Learning = 30;

        public static final int VideoPlayer = 40;

        public static final int GameStepSelect = 50;

        public static final int GameStep1 = 60;

        public static final int GameStep2 = 70;

        public static final int GameStep3 = 80;

        public static final int GameStep4 = 90;

        public static final int GameStep5 = 100;

        public static final int GameStep6 = 110;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent event) {
        onMessageEventProcess(event);
    }

    private void onMessageEventProcess(MessageEvent event) {
        if (event.getType() == MessageEventType.GameControl.PlayGameFirstLoadSound) {

        }
    }

    public void start() {
//        if (GameStep == EGameStep.FirstOpen) {
//            BackgroundMusic.instance(mContext).play(R.raw.guide_wellcome_sound, false);
//            GameStep = EGameStep.AppOpenedGameWait;
//        }
    }

    public void setStep(int gameStep) {
        if (gameStep == EGameStep.Learning) {
            BackgroundMusic.instance(mContext).stop();
        }
        GameStep = gameStep;
    }

    public int getStep() {
        return GameStep;
    }


//    private void startPlayBgSound() {
//        new DefaultHandler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//
//            }
//        }, 1000);
//    }
}
